package com.wanghua.mall.ware.controller;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Map;

import com.wanghua.mall.ware.vo.FareVo;
import org.springframework.web.bind.annotation.*;

import com.wanghua.mall.ware.entity.WareInfoEntity;
import com.wanghua.mall.ware.service.WareInfoService;
import com.wanghua.common.utils.PageUtils;
import com.wanghua.common.utils.R;

import javax.annotation.Resource;


/**
 * 仓库信息
 *
 * @author wanghua
 * @email 2367279431@qq.com
 * @date 2021-08-25 21:29:07
 */
@RestController
@RequestMapping("/ware/wareinfo")
public class WareInfoController {

    @Resource
    private WareInfoService wareInfoService;

    /**
     * 根据地址id获取运费
     *
     * @param addressId
     * @return
     */
    @GetMapping("/fare/{addressId}")
    public R getFare(@PathVariable("addressId") Long addressId) {
        FareVo fareVo = wareInfoService.getFare(addressId);
        return R.ok().put("data", fareVo);
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = wareInfoService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        WareInfoEntity wareInfo = wareInfoService.getById(id);
        return R.ok().put("wareInfo", wareInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody WareInfoEntity wareInfo) {
        wareInfoService.save(wareInfo);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody WareInfoEntity wareInfo) {
        wareInfoService.updateById(wareInfo);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        wareInfoService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
